<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://unpkg.com/vue"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" />
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .container {
      position: absolute;
      width: 200px;
      height: 400px;
      background-color: pink;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
    }
  </style>
</head>

<body>
  <div id="root"></div>
  <script>
    /* 
      1. watchj基本使用
      - 原始值与最新值
      - 对ref数据进行监听
        - 需要监听的值
      - 对reactive数据进行监听
        - 参数一 为箭头函数
      2. 同时监听多个值
      - watch函数参数一为一个数组
      3. watch是惰性执行的
      - 不会立即执行
      - 传入第三个参数{immediate: true }可实现非惰性执行
    */

    const app = Vue.createApp({
      template: `
      <div class="container" >
        <input v-model="name" />
        <input v-model="englishName" />
        {{name}} -- {{englishName}}
      </div>
    `,
      setup() {
        const { reactive, watch, toRefs } = Vue
        const nameObj = reactive({ name: '戴尔', englishName: 'dell' })
        watch([() => nameObj.name, () => nameObj.englishName], ([currentName, currentEng], [prevName, prevEng]) => {
          console.log(currentName, prevName);
          console.log(currentEng, prevEng);
        })
        const { name, englishName } = toRefs(nameObj);
        return { name, englishName }
      }
    })

    const vm = app.mount('#root');

  </script>
</body>

</html>